<template>
	<view class="wrap">
		<!-- <view style="background-color: #FFFFFF;padding-top: 100px;" v-if="!this.token">
			<u-empty text="暂无数据" mode="list"></u-empty>
		</view> -->
		<!-- 有token时的界面 -->
		<view v-if="show">
			<!-- 个人信息组件 -->
			<personal-information :userInfo='userInfo'></personal-information>
			<!-- 我的订单组件 -->
			<personal-order></personal-order>
			
			<!-- 浏览记录组件-->
			<browse-records></browse-records>
			<!-- 咨询热线组件 -->
			<hotline-consultation></hotline-consultation>
			<!-- 服务条款组件-->
			<terms-service></terms-service>
			<login-out></login-out>
		</view>
		<view v-else>
			<u-empty text="暂无数据" mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	// 导入个人信息组件
	import personalInformation from '../../commponts/personalComponents/personalInformation.vue'
	// 导入我的订单组件
	import personalOrder from '../../commponts/personalComponents/personalOrder.vue'
	// 导入浏览记录组件
	import browseRecords from '../../commponts/personalComponents/browseRecords.vue'
	//导入咨询热线组件
	import hotlineConsultation from '../../commponts/personalComponents/hotlineConsultation.vue'
	//导入服务条款组件
	import termsService from '../../commponts/personalComponents/termsService.vue'
	// 导入退出登陆组件
	import loginOut from '../../commponts/personalComponents/loginOut.vue'
	export default {
		components: {
			personalInformation,
			personalOrder,
			browseRecords,
			termsService,
			hotlineConsultation,
			loginOut
		},
		data() {
			return {
				userInfo:[],
				token:'',
				show:false
			}
		},
		mounted() {
			
		},
		methods: {
			async getUserInfo(){
				await this.$u.get('/api/user').then(res=>{
					console.log(res);
					// 获取用户的基本信息
					this.userInfo=res.data
				}).catch(err=>{
					console.log(err)
				})
			}
		},
		async onShow() {
			// 判断vuex中是否有token  
			this.token = this.vuex_token;
			if (!this.token) {
				this.show=false
				console.log(getCurrentPages())
				const currentPage=getCurrentPages().pop();
				console.log(currentPage.route)
				// 缓存当前路径
				uni.setStorageSync('back_url',currentPage.route) 
				uni.showModal({
					title: '请先登陆!!!!',
					showCancel:false,
					success: function(res) {
						if (res.confirm==true) {
							console.log(111)
							// 点击确认跳转到登陆界面
							uni.$u.route({
								type:'navigateTo',
								// url: '/page/auth/loginIn',
								url: 'pages/auth/loginIn'
							})
							// 点击取消则跳转到首页
						} else if(res.cancel){
							//  console.log('用户点击取消');
							// uni.$u.switchTab({
							// 	type:'switchTab',
							// 	// url: '/page/auth/loginIn',
							// 	url:'pages/index/index'
							// })
						}
					}
				});
			} else {
				this.getUserInfo();
				this.show=true
			}
		},
		// created() {
		// 	this.getUserInfo()
		// },
		// watch:{
		// 	userInfo:function(newValue,oldValue){
		// 		console.log(newValue);
		// 		console.log(oldValue)
		// 		this.userInfo=newValue
		// 	}
		// }
	}
</script>

<style lang="scss" scoped>
	.wrap {
		background-color: #f2f2f2;
	}
</style>
